-- half_attrib
-- create by zhuangsl
-- 生命值低于一半时，属性提升；prop[1]配置为属性时直接提升；配置为round_hp时，每回合触发并回血

return {
    apply = function(prop, baseValue)
        -- 提升的值
        local v = prop[3]
        return baseValue + v;
    end,
    
    trigger = function(who, prop, attack)
        -- 每回合触发的属性，暂时只支持回血
        if prop[2] ~= "round_hp" then
            return;
        end
        
        -- HP低于一半时触发
        local rate = math.modf(1000 * who:queryAttrib("hp") / who:queryAttrib("max_hp"));
        if rate >= 500 then
            return;
        end
        
        local attrib = "hp";
        local value  = prop[3];

        BonusM.doBonus({ 2, attrib, value, }, "prop half_attrib");

        return value;
    end,
    
    record = function(target, prop, path)
        return false;
    end
};
